﻿using System;
using System.Drawing;
namespace CapaPresentacion // Canbiar el nameSpace
{
    public static class InputBox
    {
        private static System.Windows.Forms.Form FrmInputBox;
        private static System.Windows.Forms.PictureBox PicLogo;
        private static System.Windows.Forms.Button BtnOk;
        private static System.Windows.Forms.Button BtnCancel;
        private static System.Windows.Forms.TextBox txtInput;
        private static System.Windows.Forms.Label LblPrompt;
        #region Diseo del form
        private static void CreateObj(string prompt, string Tittle, string DefaultResponse, Image Img, System.Windows.Forms.FormStartPosition Posicion)
        {
            //
            // Creamos las Instancias
            //
            FrmInputBox = new System.Windows.Forms.Form();
            PicLogo = new System.Windows.Forms.PictureBox();
            BtnOk = new System.Windows.Forms.Button();
            BtnCancel = new System.Windows.Forms.Button();
            txtInput = new System.Windows.Forms.TextBox();
            LblPrompt = new System.Windows.Forms.Label();
            FrmInputBox.SuspendLayout();
            //
            // PicLogo
            //
            if (Img != null)
            {
                //PicLogo.ImageLocation = PathImg;
                PicLogo.Image = Img;
            }
            PicLogo.Size = new System.Drawing.Size(100, 50);
            PicLogo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            PicLogo.Location = new System.Drawing.Point(190, 30);
            //
            // BtnOk
            //
            BtnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
            BtnOk.Location = new System.Drawing.Point(271, 12);
            BtnOk.Size = new System.Drawing.Size(75, 23);
            BtnOk.Text = "&Aceptar";
            BtnOk.Click += new System.EventHandler(BtnOk_Click);
            //
            // BtnCancel
            //
            BtnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            BtnCancel.Location = new System.Drawing.Point(271, 40);
            BtnCancel.Size = new System.Drawing.Size(75, 23);
            BtnCancel.Text = "&Cancelar";
            BtnCancel.Click += new System.EventHandler(BtnCancel_Click);
            //
            // txtInput
            //
            txtInput.Location = new System.Drawing.Point(7, 85);
            txtInput.Name = "txtInput";
            txtInput.Size = new System.Drawing.Size(339, 20);
            txtInput.Text = DefaultResponse; //Le paso el valor por defecto
            txtInput.ForeColor = Color.Gray;
            txtInput.Click += new System.EventHandler(txtInput_Click);
            //
            // LblPrompt
            //
            LblPrompt.AutoSize = true;
            LblPrompt.Location = new System.Drawing.Point(4, 17);
            LblPrompt.Text = prompt; //Le paso el valor por defecto
            //
            // FrmInputBox
            //
            FrmInputBox.AcceptButton = BtnOk;
            FrmInputBox.CancelButton = BtnCancel;
            FrmInputBox.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            FrmInputBox.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            FrmInputBox.AutoSize = true;
            FrmInputBox.ClientSize = new System.Drawing.Size(352, 117);
            FrmInputBox.Controls.Add(LblPrompt);
            FrmInputBox.Controls.Add(txtInput);
            FrmInputBox.Controls.Add(BtnCancel);
            FrmInputBox.Controls.Add(BtnOk);
            FrmInputBox.Controls.Add(PicLogo);
            FrmInputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            FrmInputBox.MaximizeBox = false;
            FrmInputBox.MinimizeBox = false;
            FrmInputBox.ShowIcon = false;
            FrmInputBox.ShowInTaskbar = false;
            FrmInputBox.Text = Tittle; //Le paso el valor por defecto
            FrmInputBox.StartPosition = Posicion; //Le paso el valor por defecto
            FrmInputBox.ResumeLayout(false);
            FrmInputBox.PerformLayout();
        }
        #endregion
        private static string _ibResul;
        ///

        /// Se muestra el InputBox por defecto, admite una imagen
        ///

        /// Mensaje que aparece en el formulario
        /// Titulo del formulario
        /// Valor que aparece en la caja de Texto
        /// Imagen que se va a mostar
        /// Posicion en la que se va a mostar el formulario
        /// devuelve un string
        public static string Show(string prompt, string Tittle, string DefaultResponse, Image Img, System.Windows.Forms.FormStartPosition Posicion)
        {
            if (prompt == "" | prompt == null) { prompt = "Ingrese algun Dato"; }
            if (Tittle == "" | Tittle == null) { Tittle = "sysmaxo Box"; }
            CreateObj(prompt, Tittle, DefaultResponse, Img, Posicion);
            FrmInputBox.ShowDialog();
            return IbResul;
        }
        ///

        /// Admite el InputBox por defecto
        ///

        /// Mensaje que aparece en el formulario
        /// Titulo del formulario
        /// 
        public static string Show(string prompt, string Tittle)
        {
            if (prompt == "" | prompt == null) { prompt = "Ingrese Código"; }
            if (Tittle == "" | Tittle == null) { Tittle = "Datos a Buscar"; }
            string DefaultResponse = "";
            Image Img = null;
            System.Windows.Forms.FormStartPosition Posicion = System.Windows.Forms.FormStartPosition.CenterParent;
            CreateObj(prompt, Tittle, DefaultResponse, Img, Posicion);
            txtInput.ForeColor = Color.Black;
            FrmInputBox.ShowDialog();
            return IbResul;
        }
        ///

        /// Se muestra el InputBox por defecto
        ///

        /// Devuelve un string
        public static string Show()
        {
            string prompt = "Ingrese Código", Tittle = "Datos a Buscar", DefaultResponse = "";
            Image Img = null;
            System.Windows.Forms.FormStartPosition Posicion = System.Windows.Forms.FormStartPosition.CenterParent;
            CreateObj(prompt, Tittle, DefaultResponse, Img, Posicion);
            txtInput.ForeColor = Color.Black;
            FrmInputBox.ShowDialog();
            return IbResul;
        }
        private static void BtnOk_Click(object sender, EventArgs e)
        {
            IbResul = txtInput.Text;
            FrmInputBox.Dispose();
        }
        private static void BtnCancel_Click(object sender, EventArgs e)
        {
            IbResul = null;
            FrmInputBox.Dispose();
        }
        private static void txtInput_Click(object sender, EventArgs e)
        {
            if (txtInput.ForeColor == Color.Gray)
            {
                txtInput.Clear();
                txtInput.ForeColor = Color.Black;
            }
        }
        public static string IbResul
        {
            get { return _ibResul; }
            set { _ibResul = value; }
        }
    }
}